package com.hkts.naturalgas.base.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.base.entity.*;
import com.hkts.naturalgas.base.service.IOzoneService;
import com.hkts.naturalgas.base.service.IRoastingDesulphurizingService;
import com.hkts.naturalgas.base.service.IRoastingPurifyWetElectricityService;
import com.hkts.naturalgas.utils.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.omg.CORBA.Object;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.FileInputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 焙烧脱硫
 *
 * @author yck
 * @since 2021-05-31
 */
@RestController
@RequestMapping("/instrumentdata/roastingDesulphurizing")
public class RoastingDesulphurizingController {
    private final Logger logger = LoggerFactory.getLogger(RoastingDesulphurizingController.class);

    @Autowired
    public IRoastingDesulphurizingService iRoastingDesulphurizingService;
    @Autowired
    public IRoastingPurifyWetElectricityService iRoastingPurifyWetElectricityService;
    @Autowired
    public IOzoneService iOzoneService;

    /**
     * 分页查询数据
     *
     * @param page                   分页信息
     * @param roastingDesulphurizing 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getRoastingDesulphurizingPageList")
    public Result<CustomPage> getHontUserList(Page<RoastingDesulphurizing> page, RoastingDesulphurizing roastingDesulphurizing) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iRoastingDesulphurizingService.selectPage(page, roastingDesulphurizing)));
    }

    /**
     * 保存和修改公用的
     *
     * @param roastingDesulphurizing 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/roastingDesulphurizingSave")
    public Result<Object> roastingDesulphurizingSave(RoastingDesulphurizing roastingDesulphurizing) {
        iRoastingDesulphurizingService.saveOrUpdate(roastingDesulphurizing);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/roastingDesulphurizingGetById")
    public Result<RoastingDesulphurizing> roastingDesulphurizingGetById(String id) {
        RoastingDesulphurizing byId = iRoastingDesulphurizingService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/roastingDesulphurizingDelete")
    public Result<Object> hontUserDelete(String id) {
        iRoastingDesulphurizingService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/roastingDesulphurizingBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iRoastingDesulphurizingService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    @GetMapping("/getPageByTime")
    public Result<CustomPage> getPageByTime(Page<RoastingDesulphurizing> page, String startDate, String endDate){
        return ResultUtil.data(CustomPageUtils.getCustomPage(iRoastingDesulphurizingService.selectPageByTime(page,startDate,endDate)));
    }
    /** 功能描述:
    *
    * @return:
    * @Author: 杨春科
    * @Date: 2021-06-09 8:29
    * @Description //TODO
    */
    /**
     * 功能描述:
     * 数据录入
     *
     * @return:
     * @Author: 杨春科
     * @Date: 2021-06-08 9:41
     * @Description //TODO
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/importPaperData")
    @Transactional
    public Result<Object> importPaperData(String url) throws Exception {
        File excelFile = new File(url);
        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
        HSSFSheet sheet = wb.getSheetAt(0);
       // List<RoastingDesulphurizing> list = new ArrayList<RoastingDust>(800);
        List<String> ids=new ArrayList<>();
        for (int i = 1; i < sheet.getLastRowNum(); i++) {

            HSSFRow row1 = sheet.getRow(i);
            if (row1.getCell(0) == null) {
                break;
            }
            Date dateCellValue = row1.getCell(0).getDateCellValue();
            if(dateCellValue==null){
                break;
            }
            System.out.println(dateCellValue);
            //本小时内时间列表
            List<LocalDateTime> allHourse = DataHandlerUtils.getAllHourse(dateCellValue);
            row1.getCell(0).setCellType(CellType.STRING);
            String time = row1.getCell(0).getStringCellValue();
            RoastingDesulphurizing lphuriz = new RoastingDesulphurizing();
            String id = String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId());
            ids.add(id);
            if(ids.contains(id)){
                System.out.println("id:"+id);
            }
            lphuriz.setId(id);
            lphuriz.setTime(allHourse.get(0));
            //ph值
            row1.getCell(2).setCellType(CellType.STRING);
            lphuriz.setDataPh(Float.parseFloat(row1.getCell(2).getStringCellValue()));
            //1#浆液密度
            row1.getCell(3).setCellType(CellType.STRING);
            lphuriz.setDataNd(Float.parseFloat(row1.getCell(3).getStringCellValue()));
            //一车间出入口温度
            row1.getCell(4).setCellType(CellType.STRING);
            lphuriz.setDataTe1003(Float.parseFloat(row1.getCell(4).getStringCellValue()));
            //二车间出入口温度
            row1.getCell(5).setCellType(CellType.STRING);
            lphuriz.setDataTe1002(Float.parseFloat(row1.getCell(5).getStringCellValue()));
            //3电场一次电压
            row1.getCell(6).setCellType(CellType.STRING);
            lphuriz.setDataLt(Float.parseFloat(row1.getCell(6).getStringCellValue()));
            //二氧化硫实测浓度
            row1.getCell(15).setCellType(CellType.STRING);
            lphuriz.setDataSo2(Float.parseFloat(row1.getCell(15).getStringCellValue()));
            //氮氧化物
            row1.getCell(16).setCellType(CellType.STRING);
            lphuriz.setDataNox(Float.parseFloat(row1.getCell(16).getStringCellValue()));
            //烟尘实测
            row1.getCell(17).setCellType(CellType.STRING);
            lphuriz.setDataFc(Float.parseFloat(row1.getCell(17).getStringCellValue()));
            //烟尘实测
            row1.getCell(18).setCellType(CellType.STRING);
            lphuriz.setDataO2(Float.parseFloat(row1.getCell(18).getStringCellValue()));

            //焙烧湿电电流电压部分
            RoastingPurifyWetElectricity electricity=new RoastingPurifyWetElectricity();
            electricity.setId(id);
            electricity.setTime(allHourse.get(0));
            //一电厂二次电压
            row1.getCell(8).setCellType(CellType.STRING);
            electricity.setBsjhSdv2(Float.parseFloat(row1.getCell(8).getStringCellValue()));
            //一电厂二次电流
            row1.getCell(9).setCellType(CellType.STRING);
            electricity.setBsjhSdi2(Float.parseFloat(row1.getCell(9).getStringCellValue()));
            //二电厂二次电压
            row1.getCell(10).setCellType(CellType.STRING);
            electricity.setBsjhSd2v2(Float.parseFloat(row1.getCell(10).getStringCellValue()));
            //二电厂二次电流
            row1.getCell(11).setCellType(CellType.STRING);
            electricity.setBsjhSd2i2(Float.parseFloat(row1.getCell(11).getStringCellValue()));

            //臭氧
            Ozone zone=new Ozone();
            zone.setId(id);
            zone.setTime(allHourse.get(0));
            //1#臭氧流量
            row1.getCell(13).setCellType(CellType.STRING);
            zone.setBsjhCy1(Float.parseFloat(row1.getCell(13).getStringCellValue()));
            //1#臭氧浓度
            row1.getCell(14).setCellType(CellType.STRING);
            zone.setBsjhCy1c(Float.parseFloat(row1.getCell(14).getStringCellValue()));
            //插入数据库
            iRoastingDesulphurizingService.save(lphuriz);
            iRoastingPurifyWetElectricityService.save(electricity);
            iOzoneService.save(zone);
            //Thread.sleep(5);
        }
        // iRoastingDustService.saveBatch(list);
        return ResultUtil.success("处理成功！");
    }

    /**
     * 功能描述:
     * 数据分割
     *
     * @return:
     * @Author: 杨春科
     * @Date: 2021-06-10 11:26
     * @Description //TODO
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/divisionData")
    @Transactional
    public Result<Object> divisionData() throws Exception {
        RoastingDesulphurizing phurizing = new RoastingDesulphurizing();
        List<RoastingDesulphurizing> roastingDesulphurizings = iRoastingDesulphurizingService.selectList(phurizing);
        iRoastingDesulphurizingService.deleteAll();
        for (int i = 0; i < roastingDesulphurizings.size(); i++) {
            if (i != roastingDesulphurizings.size() - 1) {
                LocalDateTime time = roastingDesulphurizings.get(i).getTime();
                System.out.println(time);
                Date date = Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
                List<LocalDateTime> allHourse = DataHandlerUtils.getAllHourse(date);
                List<RoastingDesulphurizing> list = new ArrayList<>();
                //so2
                List<Float> dataS02 = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataSo2(), roastingDesulphurizings.get(i + 1).getDataSo2());
                //nox
                List<Float> dataNox = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataNox(), roastingDesulphurizings.get(i + 1).getDataNox());
                //o2
                List<Float> dataO2 = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataO2(), roastingDesulphurizings.get(i + 1).getDataO2());
                //fc
                List<Float> datafc = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataFc(), roastingDesulphurizings.get(i + 1).getDataFc());
                //ph
                List<Float> dataph = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataPh(), roastingDesulphurizings.get(i + 1).getDataPh());
                //nd
                List<Float> dataNd = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataNd(), roastingDesulphurizings.get(i + 1).getDataNd());
                //lt
                List<Float> dataLt = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataLt(), roastingDesulphurizings.get(i + 1).getDataLt());
                //te1003
                List<Float> data1Te003 = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataTe1003(), roastingDesulphurizings.get(i + 1).getDataTe1003());
                //te1002
                List<Float> data1Te002 = DataHandlerUtils.getHandlerData(roastingDesulphurizings.get(i).getDataTe1002(), roastingDesulphurizings.get(i + 1).getDataTe1002());

                for (int j = 0; j < allHourse.size(); j++) {
                    if (j == 0) {
                        RoastingDesulphurizing roastingDesulphurizing = roastingDesulphurizings.get(i);
                        roastingDesulphurizing.setId(String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()));
                        list.add(roastingDesulphurizing);
                    } else {
                        //
                        RoastingDesulphurizing roastingDesulphurizing = new RoastingDesulphurizing();
                        roastingDesulphurizing.setId(String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()));
                        roastingDesulphurizing.setTime(allHourse.get(j));
                        roastingDesulphurizing.setDataO2(dataO2.get(j));
                        roastingDesulphurizing.setDataFc(datafc.get(j));
                        roastingDesulphurizing.setDataNox(dataNox.get(j));
                        roastingDesulphurizing.setDataLt(dataLt.get(j));
                        roastingDesulphurizing.setDataTe1003(data1Te003.get(j));
                        roastingDesulphurizing.setDataTe1002(data1Te002.get(j));
                        roastingDesulphurizing.setDataPh(dataph.get(j));
                        roastingDesulphurizing.setDataSo2(dataS02.get(j));
                        roastingDesulphurizing.setDataNd(dataNd.get(j));
                        list.add(roastingDesulphurizing);
                    }
                }
               iRoastingDesulphurizingService.saveBatch(list);
            } else {
                roastingDesulphurizings.get(i).setId(String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()));
              iRoastingDesulphurizingService.save(roastingDesulphurizings.get(i));
            }
        }
        return ResultUtil.success("处理成功！");
    }
    /** 功能描述:
    *脱硫数据导入
    * @return: 
    * @Author: 杨春科
    * @Date: 2021-06-10 15:18
    * @Description //TODO 
    */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/importPaperDataSo2")
    @Transactional
    public Result<Object> importPaperDataSo2(String url) throws Exception {
        File excelFile = new File(url);
        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
        HSSFSheet sheet = wb.getSheetAt(0);
        // List<RoastingDesulphurizing> list = new ArrayList<RoastingDust>(800);
        List<String> ids=new ArrayList<>();
        for (int i = 1; i < sheet.getLastRowNum(); i++) {

            HSSFRow row1 = sheet.getRow(i);
            if (row1.getCell(0) == null) {
                break;
            }
            Date dateCellValue = row1.getCell(0).getDateCellValue();
            if(dateCellValue==null){
                break;
            }
            System.out.println(dateCellValue);
            //本小时内时间列表
            List<LocalDateTime> allHourse = DataHandlerUtils.getAllHourse(dateCellValue);
            row1.getCell(0).setCellType(CellType.STRING);
            String time = row1.getCell(0).getStringCellValue();
            RoastingDesulphurizing lphuriz = new RoastingDesulphurizing();
            String id = String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId());
            ids.add(id);
            if(ids.contains(id)){
                System.out.println("id:"+id);
            }
            lphuriz.setId(id);
            lphuriz.setTime(allHourse.get(0));
            //ph值
            row1.getCell(8).setCellType(CellType.STRING);
            lphuriz.setDataPh(Float.parseFloat(row1.getCell(8).getStringCellValue()));
            //1#浆液密度
            row1.getCell(9).setCellType(CellType.STRING);
            lphuriz.setDataNd(Float.parseFloat(row1.getCell(9).getStringCellValue()));
            //一车间出入口温度
            row1.getCell(11).setCellType(CellType.STRING);
            lphuriz.setDataTe1003(Float.parseFloat(row1.getCell(11).getStringCellValue()));
            //二车间出入口温度
            row1.getCell(12).setCellType(CellType.STRING);
            lphuriz.setDataTe1002(Float.parseFloat(row1.getCell(12).getStringCellValue()));
            //3电场一次电压
            /*row1.getCell(6).setCellType(CellType.STRING);
            lphuriz.setDataLt(Float.parseFloat(row1.getCell(6).getStringCellValue()));*/
            //二氧化硫实测浓度
            row1.getCell(1).setCellType(CellType.STRING);
            lphuriz.setDataSo2(Float.parseFloat(row1.getCell(1).getStringCellValue()));
            //氮氧化物
            row1.getCell(2).setCellType(CellType.STRING);
            lphuriz.setDataNox(Float.parseFloat(row1.getCell(2).getStringCellValue()));
            //烟尘实测
            row1.getCell(7).setCellType(CellType.STRING);
            lphuriz.setDataFc(Float.parseFloat(row1.getCell(7).getStringCellValue()));
            //o2
            row1.getCell(3).setCellType(CellType.STRING);
            lphuriz.setDataO2(Float.parseFloat(row1.getCell(3).getStringCellValue()));
            //除雾器压力
            row1.getCell(13).setCellType(CellType.STRING);
            lphuriz.setDataPt1003(Float.parseFloat(row1.getCell(13).getStringCellValue()));
            //pt
            row1.getCell(6).setCellType(CellType.STRING);
            lphuriz.setDataPt(Float.parseFloat(row1.getCell(6).getStringCellValue()));
           //TE
            row1.getCell(5).setCellType(CellType.STRING);
            lphuriz.setDataTe(Float.parseFloat(row1.getCell(5).getStringCellValue()));
            //ft
            row1.getCell(4).setCellType(CellType.STRING);
            lphuriz.setDataFt(Float.parseFloat(row1.getCell(4).getStringCellValue()));
            //高度
            row1.getCell(10).setCellType(CellType.STRING);
            lphuriz.setDataLt(Float.parseFloat(row1.getCell(10).getStringCellValue()));
            //插入数据库
            iRoastingDesulphurizingService.save(lphuriz);

            //Thread.sleep(5);
        }
        // iRoastingDustService.saveBatch(list);
        return ResultUtil.success("处理成功！");
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/importDataUpdate")
    public Result<Object> importDataUpdate(String url) throws Exception {
        File excelFile = new File(url);
        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(2);

        List<RoastingDesulphurizing> list=new ArrayList();
        for (int i=5 ; i <sheet.getLastRowNum()-3; i++) {

            HSSFRow row1 = sheet.getRow(i);
            Date dateCellValue = row1.getCell(0).getDateCellValue();
            System.out.println(dateCellValue);
            row1.getCell(0).setCellType(CellType.STRING);
            String time=row1.getCell(0).getStringCellValue();
            QueryWrapper<RoastingDesulphurizing> query = Wrappers.query();
            query.eq(CalcinationPurifyWetElectricity.TIME,dateCellValue.toInstant()
                    .atZone( ZoneId.systemDefault() )
                    .toLocalDateTime());
            RoastingDesulphurizing one = iRoastingDesulphurizingService.getOne(query);
            if(one==null){
                continue;
            }
            row1.getCell(1).setCellType(CellType.STRING);
            one.setDataSo2(Float.parseFloat(row1.getCell(1).getStringCellValue()));
            row1.getCell(4).setCellType(CellType.STRING);
            one.setDataNox(Float.parseFloat(row1.getCell(4).getStringCellValue()));
            row1.getCell(6).setCellType(CellType.STRING);
            one.setDataO2(Float.parseFloat(row1.getCell(6).getStringCellValue()));
            row1.getCell(9).setCellType(CellType.STRING);
            one.setDataFc(Float.parseFloat(row1.getCell(9).getStringCellValue()));
            list.add(one);
            //
        }
        System.out.println("listSize:"+list.size());
        iRoastingDesulphurizingService.saveOrUpdateBatch(list);
        return ResultUtil.success("处理成功！");
    }
    /** 功能描述:
    *根据日期将多余数据删除
    * @return:
    * @Author: 杨春科
    * @Date: 2021-06-13 17:46
    * @Description //TODO
    */

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/deleteDataByTime")
    public Result<Object> deleteDataByTime(String url) throws Exception {
        File excelFile = new File(url);
        HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(excelFile));
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(2);

        List<RoastingDesulphurizing> list=new ArrayList();
        for (int i=5 ; i <sheet.getLastRowNum()-3; i++) {

            HSSFRow row1 = sheet.getRow(i);
            Date dateCellValue = row1.getCell(0).getDateCellValue();
            System.out.println(dateCellValue);
            row1.getCell(0).setCellType(CellType.STRING);
            String time=row1.getCell(0).getStringCellValue();
            RoastingDesulphurizing roastingDesulphurizing=new RoastingDesulphurizing();
            roastingDesulphurizing.setTime(dateCellValue.toInstant()
                    .atZone( ZoneId.systemDefault() )
                    .toLocalDateTime());
            List<RoastingDesulphurizing> roastingDesulphurizings = iRoastingDesulphurizingService.selectList(roastingDesulphurizing);
            for(int j=0;j<roastingDesulphurizings.size();j++){
                if(j!=0){
                    iRoastingDesulphurizingService.removeById(roastingDesulphurizings.get(j));
                }
            }
        }
        System.out.println("listSize:"+list.size());
        iRoastingDesulphurizingService.saveOrUpdateBatch(list);
        return ResultUtil.success("处理成功！");
    }

    /** 功能描述:
     *根据时间将数据补全 所有值全为0
     * @return:
     * @Author: 杨春科
     * @Date: 2021-06-17 10:49
     * @Description //TODO
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/addData")
    @Transactional
    public Result<java.lang.Object> addData( String beginDate, String endDate) throws ParseException {
        List<LocalDateTime> allMinites = DataHandlerUtils.getAllMinites(beginDate, endDate);
        List<RoastingDesulphurizing> calcinationPurificationBleachings =new ArrayList<RoastingDesulphurizing>();
        for(int i=0;i<allMinites.size();i++){
            RoastingDesulphurizing den=new RoastingDesulphurizing();
            den.setId(String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()));
            den.setTime(allMinites.get(i));
            den.setDataLt(0f);
            den.setDataTe(0f);
            den.setDataPt1003(0f);
            den.setDataPt(0f);
            den.setDataNd(0f);
            den.setDataSo2(0f);
            den.setDataNox(0f);
            den.setDataO2(0f);
            den.setDataPh(0f);
            den.setDataTe1003(0f);
            den.setDataTe1002(0f);
            den.setDataFc(0f);
            den.setDataFt(0f);
            calcinationPurificationBleachings.add(den);
        }
        iRoastingDesulphurizingService.saveBatch(calcinationPurificationBleachings);
        return ResultUtil.success("处理成功！");
    }


    /** 功能描述:
     *  根据导入数据修改压力温度压强
     * @return:
     * @Author: 杨春科
     * @Date: 2021-06-02 18:04
     * @Description //TODO
     */
    @PostMapping("/updateByImport")
    @Transactional
    public Result<Object> updateByImport(String url) throws Exception {
        File file=new File(url);
        File[] files=file.listFiles();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for(int i=0;i<files.length;i++){
            File nextfile=  files[i];
            System.out.println(nextfile.getName());
            HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(nextfile));
            HSSFSheet sheet = wb.getSheetAt(0);
            List<RoastingDesulphurizing> list=new ArrayList<RoastingDesulphurizing>(20000);
            for (int j=5;j  >= 5&&j<sheet.getLastRowNum()-4; j ++) {
                HSSFRow row1 = sheet.getRow(j);
                Date dateCellValue = row1.getCell(0).getDateCellValue();
                System.out.println(row1.getCell(0).getDateCellValue());
                RoastingDesulphurizing  bleaching=iRoastingDesulphurizingService.getOneBytime(dateCellValue);
                if(bleaching==null){
                    continue;
                }
                row1.getCell(2).setCellType(CellType.STRING);
                row1.getCell(5).setCellType(CellType.STRING);
                row1.getCell(6).setCellType(CellType.STRING);
                row1.getCell(9).setCellType(CellType.STRING);
                row1.getCell(12).setCellType(CellType.STRING);
                row1.getCell(13).setCellType(CellType.STRING);
                row1.getCell(14).setCellType(CellType.STRING);
                bleaching.setDataSo2(Float.parseFloat(row1.getCell(2).getStringCellValue()));
                bleaching.setDataNox(Float.parseFloat(row1.getCell(5).getStringCellValue()));
                bleaching.setDataO2(Float.parseFloat(row1.getCell(6).getStringCellValue()));
                bleaching.setDataFc(Float.parseFloat(row1.getCell(9).getStringCellValue()));

                bleaching.setDataFt(Float.parseFloat(row1.getCell(12).getStringCellValue()));
                bleaching.setDataTe(Float.parseFloat(row1.getCell(13).getStringCellValue()));
                bleaching.setDataPt(Float.parseFloat(row1.getCell(14).getStringCellValue()));
                list.add(bleaching);
                System.out.println(dateCellValue);

            }
           iRoastingDesulphurizingService.saveOrUpdateBatch(list);
        }

        return ResultUtil.success("成功");
    }

    @PostMapping("/handlerTimeDifferenceData")
    @Transactional
    public Result<String> handlerTimeDifferenceData(String url) throws Exception {
        File file=new File(url);
        File[] files=file.listFiles();

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date;
        for(int i=0;i<files.length;i++){
            File nextfile=  files[i];
            System.out.println(nextfile.getName());
            HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(nextfile));
            HSSFSheet sheet = wb.getSheetAt(0);
            List<RoastingDesulphurizing> list=new ArrayList<RoastingDesulphurizing>(20000);
            for (int j=5;j  >= 5&&j<sheet.getLastRowNum()-5; j ++) {
                HSSFRow row1 = sheet.getRow(j);
                Date dateCellValue = row1.getCell(0).getDateCellValue();
                HSSFRow row2 = sheet.getRow(j+1);
                Date dateCellValue2 = row2.getCell(0).getDateCellValue();
                long between = (dateCellValue2.getTime() - dateCellValue .getTime())/1000;
                long min = between/60;
                format.format(dateCellValue);
                format.format(dateCellValue2);
                if(min>1){
                    iRoastingDesulphurizingService.handlerTimeDifferenceData(format.format(dateCellValue),format.format(dateCellValue2));
                }
            }
        }

        return ResultUtil.success("处理成功");
    }
}
